package com.yike.user.controller;

import com.yike.user.entity.AgentAreaSetting;
import com.yike.user.param.AgentAreaSettingParam;
import com.yike.user.service.AgentAreaSettingService;
import com.yike.user.vo.AgentAreaInfoVo;
import com.yike.user.vo.AgentAreaVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.AgentAreaSettingPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代理商区域配置表 控制器
 *
 * @author Sakura
 * @since 2024-09-13
 */
@Slf4j
@RestController
@RequestMapping("/agentAreaSetting")
@Module("user")
@Api(value = "代理商区域配置API", tags = {"代理商区域配置管理"})
public class AgentAreaSettingController extends BaseController {

    @Autowired
    private AgentAreaSettingService agentAreaSettingService;

    /**
     * 保存代理商区域
     */
    @PostMapping("/save")
    @OperationLog(name = "保存代理商区域", type = OperationLogType.ADD)
    @ApiOperation(value = "保存代理商区域", response = ApiResult.class)
    public ApiResult<Boolean> addAgentAreaSetting(@RequestBody AgentAreaSettingParam agentAreaSettingParam) throws Exception {
        boolean flag = agentAreaSettingService.saveAgentAreaSetting(agentAreaSettingParam);
        return ApiResult.result(flag);
    }

    /**
     * 获取代理商区域配置信息
     */
    @GetMapping("/getAgentAreaSetting/{agentId}")
    //@OperationLog(name = "获取代理商区域配置信息", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商区域配置信息", response = AgentAreaVo.class)
    public ApiResult<List<AgentAreaVo>> getAgentAreaSetting(@PathVariable("agentId") Long agentId) throws Exception {
        List<AgentAreaVo> agentAreaVos = agentAreaSettingService.getAgentAreaSetting(agentId);
        return ApiResult.ok(agentAreaVos);
    }

    /**
     * 获取代理商区域信息
     */
    @GetMapping("/getAgentAreas")
    //@OperationLog(name = "获取代理商区域信息", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商区域信息", response = AgentAreaInfoVo.class)
    public ApiResult<List<AgentAreaInfoVo>> getAgentAreas() throws Exception {
        List<AgentAreaInfoVo> agentAreaInfoVos = agentAreaSettingService.getAgentAreas();
        return ApiResult.ok(agentAreaInfoVos);
    }

}

